unit MainForm;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, System.Actions, Vcl.ActnList, Vcl.Menus,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, UserManagementForm, Vcl.StdActns,
  GroupManagementForm, CustomerManagementForm, Vcl.ComCtrls, DateUtils,
  CustomerLoanSettingForm, LoginForm, Vcl.AppEvnts, Vcl.ExtCtrls, UDF,
  CustomerLoanPaymentForm, uADStanIntf, uADStanOption, uADStanError,
  uADGUIxIntf, uADPhysIntf, uADStanDef, uADStanPool, uADStanAsync,
  uADPhysManager, Data.DB, uADCompClient, uADGUIxFormsWait, uADStanParam,
  uADDatSManager, uADDAptIntf, uADDAptManager, uADCompDataSet, uADPhysMySQL,
  uADCompGUIx, uADPhysIB, Vcl.Grids, Vcl.DBGrids, Vcl.StdCtrls, Vcl.ScreenTips,
  DashBoardForm, GroupRightsForm;


type
  ///	<summary>
  ///	  MyLongLong main form
  ///	</summary>
  TfmMain = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Exit1: TMenuItem;
    Administration1: TMenuItem;
    UserManagement1: TMenuItem;
    GroupManagement1: TMenuItem;
    RightsManagement1: TMenuItem;
    Windows1: TMenuItem;
    ActionList1: TActionList;
    Close1: TMenuItem;
    Minimize1: TMenuItem;
    Maximize1: TMenuItem;
    WindowCascade1: TWindowCascade;
    WindowMinimizeAll1: TWindowMinimizeAll;
    WindowClose1: TWindowClose;
    WindowTileHorizontal1: TWindowTileHorizontal;
    ileHorizontally1: TMenuItem;
    WindowTileVertical1: TWindowTileVertical;
    ileVertically1: TMenuItem;
    WindowArrange1: TWindowArrange;
    Arrange1: TMenuItem;
    N1: TMenuItem;
    Finance1: TMenuItem;
    CustomerLoans1: TMenuItem;
    CustomerPayment1: TMenuItem;
    N2: TMenuItem;
    CashFlow1: TMenuItem;
    FileExit1: TFileExit;
    N3: TMenuItem;
    CustomerMasterInfo1: TMenuItem;
    Login1: TMenuItem;
    Logout1: TMenuItem;
    N4: TMenuItem;
    StatusBar1: TStatusBar;
    ApplicationEvents1: TApplicationEvents;
    Timer1: TTimer;
    ADConnection1: TADConnection;
    ADPhysIBDriverLink1: TADPhysIBDriverLink;
    ADGUIxWaitCursor1: TADGUIxWaitCursor;
    ADPhysMySQLDriverLink1: TADPhysMySQLDriverLink;
    adtSysVariables: TADTable;
    DashBoard1: TMenuItem;
    procedure Exit1Click(Sender: TObject);
    procedure UserManagement1Click(Sender: TObject);
    procedure GroupManagement1Click(Sender: TObject);
    procedure CustomerMasterInfo1Click(Sender: TObject);
    procedure CustomerLoans1Click(Sender: TObject);
    procedure Login1Click(Sender: TObject);
    procedure Logout1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);
    procedure Timer1Timer(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CustomerPayment1Click(Sender: TObject);
    procedure DashBoard1Click(Sender: TObject);
    procedure RightsManagement1Click(Sender: TObject);
  private
    { Private declarations }
    Duration: TTime;
  public
    { Public declarations }
    LoggedIn: boolean;
    SysVariables: TStringList;
  end;

var
  fmMain: TfmMain;

implementation

{$R *.dfm}

procedure TfmMain.ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);
begin
  if LoggedIn then
    StatusBar1.Panels[5].Text := FormatDateTime('hh:nn:ss', Duration)
  else
    StatusBar1.Panels[5].Text := '';
end;

procedure TfmMain.CustomerLoans1Click(Sender: TObject);
begin
  if not Assigned(fmCustomerLoanSetting) then
    fmCustomerLoanSetting := TfmCustomerLoanSetting.Create(Application);
  fmCustomerLoanSetting.Show;
end;

procedure TfmMain.CustomerMasterInfo1Click(Sender: TObject);
begin
  if not Assigned(fmCustomer) then
    fmCustomer := TfmCustomer.Create(Application);
  fmCustomer.Show;
end;

procedure TfmMain.CustomerPayment1Click(Sender: TObject);
begin
  if not Assigned(fmCustomerLoanPayment) then
    fmCustomerLoanPayment := TfmCustomerLoanPayment.Create(Application);
  fmCustomerLoanPayment.Show;
end;

procedure TfmMain.DashBoard1Click(Sender: TObject);
begin
  if not Assigned(fmDashBoard) then
    fmDashBoard := TfmDashBoard.Create(Application);
  fmDashBoard.Show;
end;

procedure TfmMain.Exit1Click(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TfmMain.FormCreate(Sender: TObject);
var
  ADPhysDriverLink: TADPhysDriverLink;
  DriverID: string;
begin
  DriverID := DBDriverID;
  if DriverID = 'Firebird' then
    ADPhysDriverLink := ADPhysIBDriverLink1;
  if DriverID = 'MySQL' then
    ADPhysDriverLink := ADPhysMySQLDriverLink1;
  SetDBInfo(ADConnection1, ADPhysDriverLink);

  SysVariables := TStringList.Create;
  with adtSysVariables do
  begin
    Active := True;
    First;
    while not Eof do
    begin
      SysVariables.Add(Format('%s=%s', [FieldByName('NAME').AsString, FieldByName('VALUE').AsString]));
      Next;
    end;
  end;
  Duration := StrToTime('00:00:00');
end;

procedure TfmMain.FormShow(Sender: TObject);
begin
  Login1.Click;
end;

procedure TfmMain.GroupManagement1Click(Sender: TObject);
begin
  if not Assigned(fmGroupManagement) then
    fmGroupManagement := TfmGroupManagement.Create(Application);
  fmGroupManagement.Show;
end;

procedure TfmMain.Login1Click(Sender: TObject);
begin
  if not Assigned(fmLogin) then
    fmLogin := TfmLogin.Create(Application);
  fmLogin.Show;
end;

procedure TfmMain.Logout1Click(Sender: TObject);
begin
  LoggedIn := False;
  Administration1.Visible := False;
  Finance1.Visible := False;
  Timer1.Enabled := False;
  Login1.Enabled := True;
  Logout1.Enabled := False;
  StatusBar1.Panels[1].Text := '';
  StatusBar1.Panels[3].Text := '';
  StatusBar1.Panels[5].Text := '';
end;

procedure TfmMain.RightsManagement1Click(Sender: TObject);
begin
  if not Assigned(fmGroupRights) then
    fmGroupRights := TfmGroupRights.Create(Application);
  fmGroupRights.Show;
end;

procedure TfmMain.Timer1Timer(Sender: TObject);
begin
  Duration := IncSecond(Duration, 1);
end;

procedure TfmMain.UserManagement1Click(Sender: TObject);
begin
  if not Assigned(fmUserManagement) then
    fmUserManagement := TfmUserManagement.Create(Application);
  fmUserManagement.Show;
end;

end.
